package linwen.wang.application.impl.v4;

import linwen.wang.application.OrderDetailService;
import linwen.wang.domain.OrderConvertMapper;
import linwen.wang.entity.Order;
import linwen.wang.joinMemory.service.JoinService;
import linwen.wang.service.IOrderService;
import linwen.wang.vo.OrderDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static java.util.stream.Collectors.toList;

@Service
public class OrderDetailServiceV4 implements OrderDetailService {
    @Autowired
    private OrderConvertMapper orderConvertMapper;

    @Autowired
    private IOrderService orderService;

    @Autowired
    private JoinService joinService;

    @Override
    public List<? extends OrderDetailVO> getByUserId(Long userId) {
        List<Order> orders = this.orderService.getByUserId(userId);

        List<OrderDetailVOV4> orderDetailVOS = orders.stream()
                .map(order -> new OrderDetailVOV4(orderConvertMapper.orderConvertOrderVO(order)))
                .collect(toList());

        this.joinService.joinInMemory(OrderDetailVOV4.class, orderDetailVOS);
        return orderDetailVOS;
    }
}